package com.jianyun.jyzs.widget;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
import android.widget.PopupWindow;
import android.widget.TextView;

import com.jianyun.jyzs.R;
import com.jianyun.jyzs.activity.CrmSynchroActivity;
import com.jianyun.jyzs.utils.DateDialogUtil;


/**
 * Created by mlli on 2017/8/17.
 */

public class CrmSearchPopu {
    private CrmSynchroActivity context;
    private PopupWindow popupWindow;
    private EditText title;
    private TextView stime;
    private TextView etime;
    private Button cancel;
    private Button search;

    public CrmSearchPopu(CrmSynchroActivity context) {
        this.context = context;
        initPopu(context);
    }

    private void initPopu(Context context) {
        View view = View.inflate(context, R.layout.popupwindow_crm_synchro_search, null);
        title = (EditText) view.findViewById(R.id.searchTitle);
        stime = (TextView) view.findViewById(R.id.searchStartTime);
        etime = (TextView) view.findViewById(R.id.searchEndTime);
        cancel = (Button) view.findViewById(R.id.cancelButton);
        search = (Button) view.findViewById(R.id.searchButton);
        initListener();


        popupWindow = new PopupWindow(view, ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT,true);
    }

    private void initListener() {
        etime.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                DateDialogUtil dialog = new DateDialogUtil(context, etime);
                dialog.onCreateDialog().show();
            }
        });
        stime.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                DateDialogUtil dialog = new DateDialogUtil(context, stime);
                dialog.onCreateDialog().show();
            }
        });
        cancel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                title.setText(null);
                stime.setText(null);
                etime.setText(null);
            }
        });
        search.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                String searchtitle = title.getText().toString().trim();
                String searchstime = stime.getText().toString().trim();
                String searchetime = etime.getText().toString().trim();
                context.search(searchtitle,searchstime,searchetime);
            }
        });

    }

    public void show(View view){
        popupWindow.showAsDropDown(view);

    }
}
